<!--
 * @Author: 刘晟勇
 * @Date: 2021-10-12 21:34:42
 * @LastEditTime: 2021-10-22 11:20:31
 * @Description: 购物车页面
-->
<template>
  <div class="shopcart-box">
    <!-- 头部区域 -->
    <HeaderNav class="shopcart-header">
      <template #icon>
        <i class="iconfont icon-left" @click="goback"></i>
      </template>
      <template #center>
        <span>购物车</span>
      </template>
    </HeaderNav>
    <!-- 购物车商品 -->
    <section class="shopcart-page">
      <div class="shopcart-list">
        <ShopartBox></ShopartBox>
      </div>
    </section>
    <!-- 无购物车数据界面 -->
    <div v-if="!shopCartList.length">
      <div class="shopcart-empty">
        <img
          src="//img11.360buyimg.com/jdphoto/s180x180_jfs/t18163/292/540553659/74408/adeb7463/5a93c51cN3bb5e37b.png"
        />
        <p>购物车空空如也，去逛逛吧~</p>
      </div>
    </div>
    <!-- 推荐商品 -->
    <ProductRecommend title="可能你还想要" />
    <!-- 提交订单组件 -->
    <van-submit-bar
      :price="allPrice"
      button-text="提交订单"
      @submit="onSubmit"
      v-if="shopCartList.length"
    >
      <van-checkbox
        v-model="checked"
        checked-color="#F63515"
        @click="changeAllChecked(checked)"
        >全选</van-checkbox
      >
    </van-submit-bar>
    <!-- 引用TabBar组件 -->
    <TabBar />
  </div>
</template>

<script>
// 公共组件的引用
import TabBar from "@/components/tabBar";
import HeaderNav from "@/components/header-nav";
import ShopartBox from "@/components/shopart-box";
import ProductRecommend from "@/components/product-recommend.vue";

import { mapMutations, mapGetters, mapState } from "vuex";

export default {
  name: "ShopCart",
  components: {
    TabBar,
    HeaderNav,
    ShopartBox,
    ProductRecommend,
  },
  data() {
    return {
      checked: false,
    };
  },
  computed: {
    ...mapState(["shopCartList"]),
    ...mapGetters(["allChecked", "allPrice"]),
  },
  watch: {
    allChecked() {
      if (this.allChecked) {
        this.checked = true;
      } else {
        this.checked = false;
      }
    },
    shopCartList() {
      if (!this.shopCartList.length) {
        this.checked = false;
      }
    },
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    onSubmit() {},
    ...mapMutations(["changeAllChecked"]),
  },
};
</script>

<style lang="scss" scoped>
.shopcart-box {
  background: #f7f7f7;
  padding-bottom: 100px;

  .shopcart-header {
    position: fixed;
    background: #f7f7f7;
  }

  .shopcart-page {
    margin-top: 100px;
  }

  .van-submit-bar {
    bottom: 85px;
    background-color: #f7f7f7;
    padding: 0 20px;
    @include boxSizing;
  }

  .shopcart-empty {
    width: 100%;
    padding: 60px 0;
    text-align: center;
    background: #f7f7f7;

    p {
      font-size: 30px;
      padding-top: 20px;
      color: rgba(51, 51, 51, 0.66);
    }
  }
}
</style>
